package com.weixing.mall.provider.controller.admin;

import com.google.common.collect.Lists;
import com.weixing.mall.base.constant.GlobalConstant;
import com.weixing.mall.base.wrapper.Result;
import com.weixing.mall.base.wrapper.ResultUtil;
import com.weixing.mall.core.annotation.NoRepeatSubmit;
import com.weixing.mall.base.enums.IsEnableEnum;
import com.weixing.mall.core.support.BaseController;
import com.weixing.mall.core.support.auth.SysAuth;
import com.weixing.mall.core.support.auth.SysInfo;
import com.weixing.mall.provider.model.domain.Depot;
import com.weixing.mall.provider.model.dto.DepotDto;
import com.weixing.mall.provider.model.enums.DepotTypeEunm;
import com.weixing.mall.provider.model.query.DepotQuery;
import com.weixing.mall.provider.service.IDepotService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author wx
 * @Date 2019/10/22 19:05
 * @Version 1.0
 */
@RestController
@RequestMapping("depot")
@Api(value = "仓库管理Api",tags = "仓库管理")
public class DepotController extends BaseController {
    @Autowired
    private IDepotService depotService;

    @GetMapping("")
    @ApiOperation(value = "查询")
    public Result list(){
        return ResultUtil.success(depotService.selectDepotKeeperList());
    }

    @PostMapping("/list")
    @ApiOperation(value = "条件查询")
    public Result listByQuery(DepotQuery depotQuery){
        return ResultUtil.success(depotService.selectList(initMpPage(),depotQuery));
    }
    @GetMapping("/listBySysId")
    @ApiOperation(value = "查询当前用户所负责的仓库")
    public Result listBySysId(@SysInfo SysAuth auth){
        return ResultUtil.success(depotService.listBySysId(auth.getUid(),null));
    }
    @GetMapping("/listCommityBySysId")
    @ApiOperation(value = "查询当前用户所负责的商品仓库")
    public Result listCommityBySysId(@SysInfo SysAuth auth){
        return ResultUtil.success(depotService.listBySysId(auth.getUid(),1));
    }
    @PostMapping("save")
    @ApiOperation(value = "仓库新增")
    @NoRepeatSubmit
    public Result save(DepotDto depotDto){
        depotService.create(depotDto);
        return ResultUtil.success();
    }

    @PostMapping("updateStatus")
    @ApiOperation(value = "修改状态")
    public Result updateStatus(long id, IsEnableEnum isEnable){
        depotService.updateStatus(id,isEnable);
        return ResultUtil.success();
    }

    @GetMapping("deptTypeList")
    @ApiOperation(value = "仓库分类列表")
    public Result  deptTypeList(){
        return ResultUtil.success(DepotTypeEunm.values());
    }

    @GetMapping("deptCpDepot")
    @ApiOperation(value = "仓库分类列表")
    public Result  deptCpDepot(){
        return ResultUtil.success( depotService.getDepotByCode(GlobalConstant.DepotCode.CP));
    }
    @GetMapping("leaderFrontDepot")
    @ApiOperation(value = "领导看板前端仓库信息")
    public Result leaderFrontDepot(){
        List<Depot> depotList= Lists.newArrayList();
        depotList.add(depotService.getDepotByCode("APP"));
        depotList.add(depotService.getDepotByCode("ERP"));
        return ResultUtil.success(depotList);
    }
}
